const Subscription = require("egg").Subscription;
const { Op } = require("sequelize");
class DeleteNotifi extends Subscription {
  static get schedule() {
    return {
      cron: "0 0 1 * * *",
      type: "worker",
      immediate: "false",
    };
  }

  // 删除四天前的通知
  async subscribe() {
    let time = new Date().valueOf() - 86400000 * 4;
    await this.ctx.model.Notifi.destroy({
      where: {
        created_at: {
          [Op.gt]: new Date(time),
        },
        is_read: true
      },
    });
  }
}

module.exports = DeleteNotifi;
